def prost(num):
    for i in range(2,num):
        if num%i==0:
            return False
    return True

def get():
    n=['zero','one','two','three','four','five','six','seven','eight','nine']
    us_inp=input().split()
    fin=''
    for i in range(3):
        try:
            final+=str(n.index(us_inp[i]))
        except:
            return False
    if final[0]=='0' or len(final)!=3:
        return False
    else:
        return int(final)

def last(num):
    if prost(num):
        return num
    else:
        co=1
        while co<=num:
            numP=num+co
            numM=num-co
            numPT = prost(numP)
            numMT = prost(numM)
            if numPT and numMT:
                return numP,numM
            elif numPT and not numMT:
                return numP
            elif numMT and not numPT:
                return numM
            co+=1

num=get()
if not num:
    print('Wrong Input')
else:
    print(last(num))
